feat: add ctrl+c cancellation on running pw-checks/tests#1292
Open
ferrandiaz wants to merge 25 commits into
Open
feat: add ctrl+c cancellation on running pw-checks/tests#1292ferrandiaz wants to merge 25 commits into
ferrandiaz wants to merge 25 commits into
Conversation
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
|
🎉 Experimental release successfully published on npm |
Adds an isCancelling flag to AbstractListReporter so the live status panel stops re-rendering while the cancel confirmation prompt is on screen, and resumes when the prompt closes. - onCancelPromptShown clears the panel and raises the flag. - onCancelPromptHidden lowers the flag and repaints; runs on both confirm and decline so live updates resume during the cancellation drain. - _printSummary and onStreamLogs short-circuit while the flag is up. - _clearSummary becomes a no-op when there is nothing to erase, preserving the clear/print invariant if a guard skips the paired _printSummary.
PQueue.pause() does not interrupt an in-flight handler. A CHECK_INPROGRESS handler that started before SIGINT could still emit and trigger a panel re-render right under the cancel prompt, producing spurious project-tree output. - Emit CANCEL_PROMPT_SHOWN before queue.pause(); EventEmitter.emit is synchronous so reporters set their flag before any pending handler can render. - Emit CANCEL_PROMPT_HIDDEN after the prompt resolves on both confirm and decline, restoring live updates. - On confirm, print 'Cancelling test session...' so the user sees feedback while the backend cancellation completes. - Always queue.start() after the prompt: drains MQTT results so allChecksFinished can resolve on confirm, resumes normal flow on decline. - Use printLn instead of raw process.stdout.write to match the rest of the CLI.
Wires the runner's CANCEL_PROMPT_SHOWN and CANCEL_PROMPT_HIDDEN events to each reporter for the test, pw-test, and trigger commands.
Covers happy paths (clear-then-repaint, normal render before/after the prompt) and edge cases (empty _clearString no-op, double prompt-shown idempotency, prompt-hidden without prior prompt-shown, suppression of _printSummary and onStreamLogs while cancelling).
sorccu
reviewed
May 20, 2026
The fixture doesn't import any project code — it only tests prompts library behavior, which is already covered by the abstract-check-runner unit tests. Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>
Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>
fff12f3 to
e5ab7af
Compare
Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>
The interactive confirmation prompt on Ctrl+C broke on Windows due to cmd.exe's competing "Terminate batch job" dialog and the `when-exit` transitive dependency (conf → atomically → when-exit) preempting the SIGINT handler. Now Ctrl+C always cancels immediately and suggests --detach for keeping checks running. Uses prependListener to run before when-exit's handler. Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>
…ve prompt The interactive confirmation prompt on Ctrl+C conflicted with cmd.exe's "Terminate batch job" prompt on Windows, and a transitive dependency (when-exit via conf → atomically) preempted the SIGINT handler by re-raising SIGINT, which is a hard kill on Windows. Replace the prompt with immediate cancellation: first Ctrl+C emits CANCEL and shows a message suggesting --detach, second Ctrl+C force exits. The cancellation message is rendered by the reporter as part of its live summary panel so it doesn't get overwritten. Pre-existing SIGINT listeners are removed during the run and restored afterward to prevent when-exit from terminating the process. Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>
Ctrl+C with --detach now shows "Checks will continue running in the cloud." before exiting, instead of silently terminating. Also refactors the SIGINT handler setup: both detach and non-detach modes share the same when-exit listener removal and registration code, with the mode-specific behavior inside the handler body. Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>
The cancel endpoint returns 403 when the account doesn't have the feature flag set. Silently ignore it since cancellation is best-effort. Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>
sorccu
approved these changes
May 20, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Affected Components
Notes for the Reviewer
Pressing Ctrl-C during
checkly pw-test,checkly test, orcheckly triggernow cancels the in-flight test session server-side via a new/v1/cancelREST endpoint, instead of silently killing the CLI and leaving the remote session running.Motivation
Before this change, Ctrl-C terminated the CLI without signalling the backend — the remote session kept consuming cloud resources with no way to stop it.
What changed
CancelREST client (rest/cancel.ts) —POST /v1/cancelviacancelTestSessionandcancelCheckSession; registered asapi.cancelinapi.tsAbstractCheckRunner— on first Ctrl+C: emitsEvents.CANCELand the reporter shows a cancellation message with a--detachhint; on second Ctrl+C: force-exits with code 1. Pre-existing SIGINT listeners (fromwhen-exit, a transitive dependency) are removed during the run and restored afterward to prevent them from terminating the process on Windows.--detachflag — when used, first Ctrl+C shows "Checks will continue running in the cloud." and exits cleanly with code 0 (checks keep running server-side)pw-test,test,trigger) wireEvents.CANCELandEvents.DETACHto reporters and the cancel APIonCancel/onDetachlifecycle on theReporterinterface; cancellation/detach messages rendered as part of the live summary panel;CheckStatus.CANCELLEDwith⊘symbol; cancelled-count in summary lineTests
Unit tests across cancel client (4), runner SIGINT lifecycle (9), reporter cancel/detach UI (4), util (24).
Notes
cancelCheckSessionis wired but not called from any command in this PR — reserved for a future integrationReporterimplementations outside this repo need stubs foronCancel()andonDetach()